package studio7.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import studio7.exception.DAOException;
import studio7.negocio.AdministradorNegocio;

@WebServlet("/armadoSala1")
public class ArmadoSala1 extends HttpServlet{

	private static final long serialVersionUID = 1L;

	public void service(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException{
		final String log = "[ ArmadoSala1.service ] ";
		System.out.println(log + "INICIO");
		HttpSession session = request.getSession(true);
		Object obj = session.getAttribute("s");
		//LLenado de combos Sala, Servicios e Instrumentos
		if(obj == null){
			AdministradorNegocio an = new AdministradorNegocio();
			try {
				session.setAttribute("arraySala", an.listarSala2());
				session.setAttribute("arrayServicio", an.listarServicios2());
				session.setAttribute("arrayInstrumento", an.listarInstrumentos2());
				request.getRequestDispatcher("/armadoSala1.jsp").forward(request, resp);
			} catch (DAOException e) {
				System.out.println(log + "DAOException: " + e);
			}
			session.setAttribute("s", "1");
		}else{//Redireccionamiento al Registro de Instrumentos
			String idSala = request.getParameter("idSala"),
				   idServicio = request.getParameter("idServicio"),
				   costoXHora = request.getParameter("costoXHora");
			System.out.println(log+ "Datos seleccionados:");
			System.out.println(log + "idSala --> " + idSala);
			System.out.println(log + "idServicio --> " + idServicio);
			System.out.println(log + "costoXHora --> " + costoXHora);
			
			session.setAttribute("idSala", idSala);
			session.setAttribute("idServicio", idServicio);
			session.setAttribute("costoXHora", costoXHora);
			
			request.getRequestDispatcher("/armadoSala2.jsp").forward(request, resp);
		}
		System.out.println(log + "FIN");
	}
}